{extend name="layout/plugin_layout" /}
﻿
{block name="title"}{$plugin.title} - {$app.title}{/block}
{block name="head"}
<script src="{:cdnjs_cdn()}/crypto-js/4.1.1/crypto-js.min.js"></script>
{/block}
{block name="main"}
<div class="container mx-auto" id="app">
    <div class="card lg:card-side bordered shadow-lg">
        <div class="card-body overflow-auto">
            <div class="main">
                <div class="form-control">
                    <label class="label">
                        <span class="label-text">字符串</span>
                    </label>
                    <textarea v-model="set.input" class="textarea textarea-bordered  h-64"></textarea>
                </div>
                <div class="card-actions mt-4">
                    <button class="btn btn-primary flex-1" @click="encode">
                        <svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6" fill="none" viewBox="0 0 24 24"
                             stroke="currentColor">
                            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
                                  d="M17 13l-5 5m0 0l-5-5m5 5V6"/>
                        </svg>
                        编码
                    </button>
                    <button class="btn btn-primary flex-1" @click="decode">
                        <svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6" fill="none" viewBox="0 0 24 24"
                             stroke="currentColor">
                            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
                                  d="M17 13l-5 5m0 0l-5-5m5 5V6"/>
                        </svg>
                        解码
                    </button>
                    <button class="btn btn-primary flex-1" @click="reset">
                        <svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5" viewBox="0 0 20 20" fill="currentColor">
                            <path fill-rule="evenodd"
                                  d="M4 2a1 1 0 011 1v2.101a7.002 7.002 0 0111.601 2.566 1 1 0 11-1.885.666A5.002 5.002 0 005.999 7H9a1 1 0 010 2H4a1 1 0 01-1-1V3a1 1 0 011-1zm.008 9.057a1 1 0 011.276.61A5.002 5.002 0 0014.001 13H11a1 1 0 110-2h5a1 1 0 011 1v5a1 1 0 11-2 0v-2.101a7.002 7.002 0 01-11.601-2.566 1 1 0 01.61-1.276z"
                                  clip-rule="evenodd"/>
                        </svg>
                        清空
                    </button>
                </div>
                <div class="flex flex-col xl:flex-row">
                    <div class="form-control flex-1">
                        <label class="label">
                            <span class="label-text">encodeURI编码,不会对特殊符号编码</span>
                        </label>
                        <textarea v-model="set.output.encodeURI" class="textarea textarea-bordered  h-64"></textarea>
                    </div>
                    <div class="form-control flex-1">
                        <label class="label">
                            <span class="label-text">encodeURIComponent编码方式，会对特殊符号编码</span>
                        </label>
                        <textarea v-model="set.output.encodeURIComponent"
                                  class="textarea textarea-bordered  h-64"></textarea>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<script>
    new Vue({
        el: '#app',
        data: {
            set: {
                input: '',
                output: {
                    encodeURI: '',
                    encodeURIComponent: '',
                },
            },
        },
        created() {
        },
        methods: {
            encode() {
                try {
                    this.set.output.encodeURI = encodeURI(this.set.input)
                    this.set.output.encodeURIComponent = encodeURIComponent(this.set.input)
                } catch (e) {
                    $message.error(e.message)
                }
            },
            decode() {
                try {
                    this.set.output.encodeURI = decodeURI(this.set.input)
                    this.set.output.encodeURIComponent = decodeURIComponent(this.set.input)
                } catch (e) {
                    $message.error(e.message)
                }

            },
            reset() {
                this.set.input = ''
                this.set.output = {
                    encodeURI: '',
                    encodeURIComponent: '',
                }

            },
        },
    })

</script>

{/block}